﻿

namespace SvGame.Objects;

// 存活状态
public enum ELiveState
{
    Living = 0, // 存活
    Unconcious = 1, // 昏迷
    Die = 2, // 死亡
}


public partial class CombatData
{
    // 比试对手
    public List<long> EnemyList = new();
    // 仇人
    public List<long> KillingList = new();

    // 上个造成伤害的单位
    public IRole LastDamageFrom = null;

    #region Actions

    public Equip Weapon = null; // 武器
    // 装备兵器类型
    public EWeaponType ActEquipWeaponType = EWeaponType.无;
    // 对应兵器技能
    public EUsageType ActEquipUsageType = EUsageType.扑击格斗;
    public string ActEquipWeaponName = "";

    public List<ConfigCbtAction> ActList = new();
    public ConfigCbtAction ActUse = new();

    public string ActWeaponName = "";

    public List<string> ActParryMsgs = new();// 招架描述列表

    // 施放perform时的招式
    public string PerformActName = string.Empty;

    #endregion

    #region Busy

    // 忙乱结束ticks
    public long BusyTicksEnd = 0;
    // 忙乱豪秒
    public int BusyMs = 0;

    public bool IsBusy => BusyIn();
    public bool BusyIn()
    {
        if (BusyMs <= 0)
        {
            return false;
        }
        if (DateTime.Now.Ticks >= BusyTicksEnd)
        {
            BusyTicksEnd = 0;
            BusyMs = 0;
            return false;
        }
        return true;
    }
    // 忙乱开始 毫秒
    public void BusyStart(int ms, bool busynew = true)
    {
        if (ms <= 0)
        {
            return;
        }
        var dtNow = DateTime.Now;
        if (!IsBusy || busynew)
        {
            BusyTicksEnd = dtNow.AddMilliseconds(ms).Ticks;
            BusyMs = ms;
        }
        else
        {
            BusyTicksEnd += ms * TimeSpan.TicksPerMillisecond;
            BusyMs += ms;
        }
    }
    // 忙乱结束
    public void BusyStop()
    {
        BusyTicksEnd = 0;
        BusyMs = 0;
    }

    #endregion

    #region Cd

    // cd结束ticks
    public Dictionary<string, long> CdTicksEnd = new();
    public bool IsCd(string perform)
    {
        var dtNow = DateTime.Now;
        if (CdTicksEnd.TryGetValue(perform, out var ticks))
        {
            return dtNow.Ticks < ticks;
        }
        return false;
    }
    public void CdStart(string perform, int sec)
    {
        if (sec <= 0)
        {
            return;
        }
        CdTicksEnd[perform] = DateTime.Now.AddSeconds(sec).Ticks;
    }

    #endregion

    #region Combat

    public bool Guarding = false;

    #endregion

    #region Prop

    // 装备属性
    public Props PropsEquip = new();
    // 状态属性
    public Props PropsBuff = new();
    // 状态标记
    public List<string> PropsBuffFlags = new();

    #endregion

    #region Live 存活状态
    public ELiveState LiveState { get; set; }

    #endregion


}
